package com.leoman.dao;

import com.leoman.entity.UserCollect;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * UserCollectDao
 * Created by 涂奕恒 on 2016/11/23 0023 下午 3:46.
 */
public interface UserCollectDao extends JpaRepository<UserCollect, Integer>, JpaSpecificationExecutor<UserCollect> {

    @Query("select a from UserCollect a where a.user.id = ?1 and a.sourceId = ?2 and a.sourceType = ?3")
    UserCollect findOneByParams(Integer userId, Integer sourceId, Integer type);

    @Query("select a from UserCollect a where a.user.id = ?1 and a.sourceType = ?2")
    Page<UserCollect> iPageByUserId(Integer userId, Integer type, Pageable pageable);

    @Query("select a from UserCollect a where a.sourceId = ?1 and a.sourceType = ?2")
    List<UserCollect> findListBySourceIdAndType(Integer sourceId, Integer type);
}